<?php
namespace app\admin\controller;

use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;


class Loan extends Controller
{
    public function index(){
        return $this->fetch();
    }
    public function loan(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        //$operation['operation']=$user = session('user.name');
        $data['agreement'] = 1;
        $res=db('bystages')->where($data)->order('id Desc')->paginate(10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        //dump($res);exit;
        return $this->fetch();
    }
    public function loan_insert(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
            return $this->fetch();
    }
    public function expressadd(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            $this->success('提交不能为空', 'express');
        }
        //$data = $_POST;
        //dump($_POST);exit;
//        $data['operation'] = session('user.name');
        $data['memberid'] = trim(input('memberid'));
        $data['bankname'] = trim(input('bankname'));
        $data['bankaccount'] = trim(input('bankaccount'));
        $data['bankaddress'] = trim(input('bankaddress'));
        $data['examine'] = trim(input('examine'));
        $data['time'] = time();
        //dump($_POST);exit;
        $res=db('loan')->insert($data);
        if($res){
            echo "<script>alert('添加信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'添加信息成功'];
        }else{
            echo "<script>alert('添加信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'添加信息失败'];
        }
    }
    public function expressdelete(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
        }
        $data['id'] = trim($_GET['id']);
        $res=db('loan')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            return ['code'=>1,'msg'=>'删除信息成功'];
        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];
        }
    }
    public function loan_det(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $data['id'] = trim(input('id'));
        $res=db('bystages')->where($data)->find();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function loan_dett(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $data['id'] = trim(input('id'));
        $res=db('short')->where($data)->find();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function expressupdate(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
            //$this->success('提交不能为空', 'express');
            //return ['code'=>2,'msg'=>'提交不能为空'];
        }
//dump($_POST);exit;
        $id['id'] = trim(input('id'));
        //$data = $_POST;
        //$data['operation'] = session('user.name');
//        $data['memberid'] = trim(input('memberid'));
//        //$data['bankname'] = trim(input('bankname'));
//        $data['bankaccount'] = trim(input('bankaccount'));
//        $data['bankaddress'] = trim(input('bankaddress'));
//        $data['examine'] = trim(input('examine'));
//        $data['emergencycontact1'] = trim(input('emergencycontact1'));
//        $data['emergencycontact2'] = trim(input('emergencycontact2'));
//        $data['emergencycontact3'] = trim(input('emergencycontact3'));
//        //$data[''] = trim(input());
//        $data['time'] = time();
        $data=$_POST;
        //dump($_POST);exit;
        //dump($data);exit;
        //dump($_POST);exit;
        $res=db('bystages')->where($id)->update($data);
        if($res){
            echo "<script>alert('更新信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'更新成功'];
        }else{
            echo "<script>alert('更新信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'更新失败'];
        }
    }
    public function expressupdatee(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
            //$this->success('提交不能为空', 'express');
            //return ['code'=>2,'msg'=>'提交不能为空'];
        }
//dump($_POST);exit;
        $id['id'] = trim(input('id'));
        //$data = $_POST;
        //$data['operation'] = session('user.name');
//        $data['memberid'] = trim(input('memberid'));
//        //$data['bankname'] = trim(input('bankname'));
//        $data['bankaccount'] = trim(input('bankaccount'));
//        $data['bankaddress'] = trim(input('bankaddress'));
//        $data['examine'] = trim(input('examine'));
//        $data['emergencycontact1'] = trim(input('emergencycontact1'));
//        $data['emergencycontact2'] = trim(input('emergencycontact2'));
//        $data['emergencycontact3'] = trim(input('emergencycontact3'));
//        //$data[''] = trim(input());
//        $data['time'] = time();
        $data=$_POST;
        //dump($_POST);exit;
        //dump($data);exit;
        //dump($_POST);exit;
        $res=db('bystages')->where($id)->update($data);
        if($res){
            echo "<script>alert('更新信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'更新成功'];
        }else{
            echo "<script>alert('更新信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'更新失败'];
        }
    }
    public function loandelete(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            $this->success('提交不能为空','express');
        }
        $data['id'] = trim(input('id'));
        //dump($data);exit;
        $res=db('bystages')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];
        }
    }
    public function loandeletee(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            $this->success('提交不能为空','express');
        }
        $data['id'] = trim(input('id'));
        //dump($data);exit;
        $res=db('short')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];
        }
    }
    public function loan_examine(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$operation['operation']=$user = session('user.name');
        $data['agreement'] = 1;
        $res=db('short')->where($data)->order('id Desc')->paginate(10);
        $page =  $res->render();
        //dump($res);exit;
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();
    }
}